import 'dart:async';

import 'package:flustars/flustars.dart';
import 'package:lishopflu/base/view_import.dart';
import 'package:lishopflu/entity/address_bean.dart';
import 'package:lishopflu/base/controller_import.dart';


class AddressChooseCtl extends BaseListController<AddressBean>{

  var addressBean = AddressBean.init().obs;

  @override
  void onFirst() {
    if(appArguments!=null && appArguments.obj!=null){
      changeItem(appArguments.obj);
    }
    callRefresh();
  }

  @override
  void onDestroy() {

  }

  /*
    选中
   */
  void checkItem(){
    if(addressBean.value.id > 0){
      for(AddressBean bean in mList){
        if(addressBean.value.id == bean.id){
          bean.check = '1';
        }else{
          bean.check = '0';
        }
      }
    }
  }

  void changeItem(AddressBean item){
    addressBean.value = item;
    checkItem();
  }

  bool isCheck(AddressBean item){
    return item.id == addressBean.value.id && StringUtil.text(addressBean.value.check) == '1';
  }

  @override
  void getList(FutureOr<AddressBean> Function(List<AddressBean> value) onValue) {
    LocalJson.addressList().then((value){
      onValue.call(JsonUtil.getObjList(value, (v) => AddressBean.fromJson(v)));
      checkItem();
    });
  }




}